package chunmap.orm.mapping.type;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import chunmap.util.ChunDaoException;

public class BooleanType  implements DataType {
	@Override
	public String toString() {
		return "boolean";
	}

	@Override
	public void setPreparedStatement(PreparedStatement ps, int parameterIndex,
			Object obj) {
		try {
			if(obj==null){
				ps.setNull(parameterIndex, java.sql.Types.BOOLEAN);
				return;
			}
			Boolean value = (Boolean) obj;
			ps.setBoolean(parameterIndex, value);

		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}

	@Override
	public Object readData(ResultSet rs, int parameterIndex) {
		try {
			Boolean i= rs.getBoolean(parameterIndex);
			//if(rs.wasNull())return null;
			return i;
		} catch (SQLException e) {
			throw new ChunDaoException(e);
		}
	}
}
